#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Git部分克隆工具使用示例
"""

from git_partial_clone import GitPartialClone

def example_basic_usage():
    """基本使用示例"""
    print("=== 基本使用示例 ===")
    
    # 创建克隆器实例
    cloner = GitPartialClone()
    
    # 配置仓库信息
    source_repo = "https://github.com/username/test.git"
    target_repo = "https://github.com/username/test1.git"
    directory_path = "people/student/computer"
    
    # 执行传输
    success = cloner.transfer_directory(
        source_repo=source_repo,
        target_repo=target_repo,
        directory_path=directory_path
    )
    
    if success:
        print("✅ 传输成功！")
    else:
        print("❌ 传输失败！")

def example_with_custom_branch():
    """指定分支的使用示例"""
    print("\n=== 指定分支示例 ===")
    
    cloner = GitPartialClone()
    
    success = cloner.transfer_directory(
        source_repo="https://github.com/username/test.git",
        target_repo="https://github.com/username/test1.git",
        directory_path="people/student/computer",
        source_branch="develop",  # 从develop分支克隆
        commit_message="Sync computer directory from develop branch"
    )
    
    if success:
        print("✅ 从develop分支传输成功！")
    else:
        print("❌ 传输失败！")

def example_multiple_directories():
    """传输多个目录的示例"""
    print("\n=== 多目录传输示例 ===")
    
    directories = [
        "people/student/computer",
        "people/student/books",
        "people/teacher/materials"
    ]
    
    source_repo = "https://github.com/username/test.git"
    target_repo = "https://github.com/username/test1.git"
    
    for directory in directories:
        print(f"\n正在传输目录: {directory}")
        cloner = GitPartialClone()
        
        success = cloner.transfer_directory(
            source_repo=source_repo,
            target_repo=target_repo,
            directory_path=directory,
            commit_message=f"Sync {directory} directory"
        )
        
        if success:
            print(f"✅ {directory} 传输成功！")
        else:
            print(f"❌ {directory} 传输失败！")

def example_with_authentication():
    """使用认证的示例（需要配置Git凭据）"""
    print("\n=== 私有仓库认证示例 ===")
    print("注意：使用私有仓库前，请确保已配置Git凭据")
    print("可以使用以下方式之一：")
    print("1. git config --global credential.helper store")
    print("2. 使用SSH密钥")
    print("3. 使用Personal Access Token")
    
    # 使用Personal Access Token的URL格式
    # source_repo = "https://username:token@github.com/username/private-test.git"
    # target_repo = "https://username:token@github.com/username/private-test1.git"
    
    # 或者使用SSH格式
    source_repo = "git@github.com:username/test.git"
    target_repo = "git@github.com:username/test1.git"
    
    cloner = GitPartialClone()
    
    success = cloner.transfer_directory(
        source_repo=source_repo,
        target_repo=target_repo,
        directory_path="people/student/computer"
    )
    
    if success:
        print("✅ 私有仓库传输成功！")
    else:
        print("❌ 私有仓库传输失败！")

def main():
    """运行所有示例"""
    print("Git部分克隆工具使用示例")
    print("=" * 50)
    
    # 注意：在实际使用前，请修改仓库URL为真实的仓库地址
    print("⚠️  注意：请在运行前修改示例中的仓库URL为真实地址")
    print("⚠️  确保你有目标仓库的写入权限")
    print()
    
    # 运行基本示例（注释掉以避免实际执行）
    # example_basic_usage()
    # example_with_custom_branch()
    # example_multiple_directories()
    # example_with_authentication()
    
    print("示例代码已准备就绪，请根据需要取消注释并修改仓库URL后运行")

if __name__ == "__main__":
    main()